package cn.gdrj.est.util;

import java.util.ArrayList;
import java.util.List;

/**
 * TODO(这里用一句话描述这个类的作用)
 *
 * @author jun
 * @date 2021/11/9
 */
public class BeanUtils {

    public static <S,T> T convertToDTO(S source,Class<T> clz){
        try {
            T target = clz.newInstance();
            org.springframework.beans.BeanUtils.copyProperties(source,target);
            return target;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    public static <S,T> List<T> convertToDTOList(List<S> sources, Class<T> clz){
        List<T> dtos = new ArrayList<>();
        for (S source : sources) {
            T dto = convertToDTO(source, clz);
            dtos.add(dto);
        }
        return dtos;
    }
}
